
package com.vanda.db.cfg;
import java.util.HashMap;
import com.vanda.db.util.MapUtils;

/**
 * DB配置数据类 <br>
 * @author 王瑛 <br>
 * @version Version 1.00 <br>
 */
public class ConfigBean {
	/** 保存Hibernate配置文件信息 key=name value=resource */
	static HashMap hibernate = null;
	
	/** 保存Property元素信息  */
	static HashMap property = null;
	
	/** Hibernate Mapping配置文件信息 key=name value=MappingInfo */
	static HashMap mapfiles = null;
	
	static {
		hibernate = new HashMap(5);
		property = new HashMap(10);
		mapfiles = new HashMap();
	}
	
	public static HashMap getHibernate() {
		return hibernate;
	}

	public static HashMap getProperty() {
		return property;
	}

	public static void setHibernate(HashMap map) {
		hibernate = map;
	}

	public static void setProperty(HashMap map) {
		property = map;
	}
	/**
	 * 查找name对应的mappingInfo,name格式为[namespace:name]
	 * @param name
	 * @return
	 */
	public static MappingInfo findMappingInfo(String name) {
		MappingInfo info = null;
		int index = name.indexOf(Environment.SYMBOL);
		if (index < 0) {
			return null;
		}
		String namespace = name.substring(0, index);
		MappingBean bean = (MappingBean) MapUtils.getValue(mapfiles, namespace);
		if (bean == null) {
			return null;
		}
		name = name.substring(index + 1, name.length());
		info = (MappingInfo) MapUtils.getValue(bean.getMapping(), name);
		return info;
	}
}
